package base.utils

import android.content.Context
import android.media.SoundPool
import android.view.View
import java.util.HashMap

/**
 * Created by Administrator on 2018/4/24.
 */
object FocusUtils {

    private val mSoundPool: SoundPool? = null
    private val soundID: HashMap<Int, Int>? = null

    fun changeFocus(view: View?) {
        if (view == null) return
        view.isFocusableInTouchMode = true
        view.requestFocus()
        view.isFocusableInTouchMode = false
    }

    fun changeFocus(view: View?, context: Context) {
        //        mSoundPool = null;
        //        soundID = new HashMap<Integer, Integer>();
        //
        //        if (Build.VERSION.SDK_INT >= 21) {
        //            SoundPool.Builder builder = new SoundPool.Builder();
        //            //传入音频数量
        //            builder.setMaxStreams(5);
        //            //AudioAttributes是一个封装音频各种属性的方法
        //            AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
        //            //设置音频流的合适的属性
        //            attrBuilder.setLegacyStreamType(AudioManager.STREAM_MUSIC);
        //            //加载一个AudioAttributes
        //            builder.setAudioAttributes(attrBuilder.build());
        //            mSoundPool = builder.build();
        //        }
        //        //当系统的SDK版本小于21时
        //        else {//设置最多可容纳2个音频流，音频的品质为5
        //            mSoundPool = new SoundPool(5, AudioManager.STREAM_SYSTEM, 5);
        //        }
        //        soundID.put(1, mSoundPool.load(context, R.raw.ssss, 1));
        //        //soundID.put(2, mSoundPool.load(getAssets().openFd("assets.mp3"), 1));  //需要捕获IO异常

        if (view != null) {
            view.isFocusableInTouchMode = true
            view.requestFocus()
            view.isFocusableInTouchMode = false
        }

        //        new android.os.Handler().postDelayed(new Runnable() {
        //            @Override
        //            public void run() {
        //                mSoundPool.play(soundID.get(1), 1, 1, 0, 0, 1);
        //            }
        //        },150);

    }

}